package newcoder.JZ48;

import java.util.ArrayList;
import java.util.List;

//abcabcbb
public class Solution {

    public static void main(String[] args) {
        String s = "pwwkew";
        System.out.println(lengthOfLongestSubstring(s));
    }

    public static int lengthOfLongestSubstring (String s) {
        // write code here
        char[] chars = s.toCharArray();
        if (s.isEmpty()){
            return 0;
        }
        int[] d = new int[s.length()];
        int max = 1;
        List<Character> list = new ArrayList<>();
        list.add(chars[0]);
        for (int i = 1; i < s.length(); i++) {
            int existIndex = list.indexOf(chars[i]);
            if (existIndex == -1){
                list.add(chars[i]);
            }
            else{
                for (int j = 0; j <=existIndex; j++) {
                    list.remove(0);
                }
                list.add(chars[i]);
            }
                if (list.size()>max){
                    max = list.size();
                }
        }
        return max;
    }
}
